package com.zhaoxi.project.md.service.impl;

import com.zhaoxi.project.md.domain.MdPartner;
import com.zhaoxi.project.md.mapper.MdPartnerMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 合作伙伴Service业务层处理
 *
 * @author zhaoxi
 * @date 2023-07-07
 */
@Service
public class MdPartnerServiceImpl {
    @Autowired
    private MdPartnerMapper mdPartnerMapper;

    /**
     * 查询合作伙伴
     *
     * @param id 合作伙伴主键
     * @return 合作伙伴
     */

    public MdPartner selectMdPartnerById(Long id) {
        return mdPartnerMapper.selectMdPartnerById(id);
    }

    /**
     * 查询合作伙伴列表
     *
     * @param mdPartner 合作伙伴
     * @return 合作伙伴
     */

    public List<MdPartner> selectMdPartnerList(MdPartner mdPartner) {
        return mdPartnerMapper.selectMdPartnerList(mdPartner);
    }

    /**
     * 新增合作伙伴
     *
     * @param mdPartner 合作伙伴
     * @return 结果
     */

    public int insertMdPartner(MdPartner mdPartner) {
        return mdPartnerMapper.insertMdPartner(mdPartner);
    }

    /**
     * 修改合作伙伴
     *
     * @param mdPartner 合作伙伴
     * @return 结果
     */

    public int updateMdPartner(MdPartner mdPartner) {
        return mdPartnerMapper.updateMdPartner(mdPartner);
    }

    /**
     * 批量删除合作伙伴
     *
     * @param ids 需要删除的合作伙伴主键
     * @return 结果
     */

    public int deleteMdPartnerByIds(Long[] ids) {
        return mdPartnerMapper.deleteMdPartnerByIds(ids);
    }

    /**
     * 删除合作伙伴信息
     *
     * @param id 合作伙伴主键
     * @return 结果
     */

    public int deleteMdPartnerById(Long id) {
        return mdPartnerMapper.deleteMdPartnerById(id);
    }


    public MdPartner selectCrmLeadById(Long id) {
        return mdPartnerMapper.selectCrmLeadById(id);
    }

    public MdPartner selectCrmLeadByMobile(MdPartner crmLead) {
        return mdPartnerMapper.selectMdPartnerByMobile(crmLead);
    }

    /**
     * 查询客户跟踪列表
     *
     * @param crmLead 客户跟踪
     * @return 客户跟踪
     */

    public List<MdPartner> selectCrmLeadList(MdPartner crmLead) {
        return mdPartnerMapper.selectCrmLeadList(crmLead);
    }

    /**
     * 新增客户跟踪
     *
     * @param crmLead 客户跟踪
     * @return 结果
     */

    public int insertCrmLead(MdPartner crmLead) {
        this.insertLeadComment(crmLead);
        return mdPartnerMapper.insertCrmLead(crmLead);
    }

    /**
     * 修改客户跟踪
     *
     * @param crmLead 客户跟踪
     * @return 结果
     */

    public int updateCrmLead(MdPartner crmLead) {
        //如果没有就调用新增。
        if (mdPartnerMapper.selectCrmLeadById(crmLead.getId()) == null) {
            return this.insertCrmLead(crmLead);
        } else {
            this.insertLeadComment(crmLead);
            return mdPartnerMapper.updateCrmLead(crmLead);
        }
    }

    /**
     * 批量删除客户跟踪
     *
     * @param ids 需要删除的客户跟踪主键
     * @return 结果
     */

    public int deleteCrmLeadByIds(Long[] ids) {
        return mdPartnerMapper.deleteCrmLeadByIds(ids);
    }

    /**
     * 删除客户跟踪信息
     *
     * @param id 客户跟踪主键
     * @return 结果
     */

    public int deleteCrmLeadById(Long id) {
        return mdPartnerMapper.deleteCrmLeadById(id);
    }

    public MdPartner selectMdPartnerByMobile(MdPartner mdPartner) {
        return mdPartnerMapper.selectMdPartnerByMobile(mdPartner);
    }

    public List<MdPartner> selectCrmLeadCommentList(MdPartner mdPartner) {
        List<MdPartner> ListmdPartner = mdPartnerMapper.selectCrmLeadCommentList(mdPartner);
        return ListmdPartner;
    }
    public int insertLeadComment(MdPartner mdPartner) {
        if (mdPartner.getSalesStage()==null){
            mdPartner.setSalesStage("1");
        }
        return mdPartnerMapper.insertLeadComment(mdPartner);
    }

    public MdPartner selectCrmLeadResumeInfo(Long id) {
        return mdPartnerMapper.selectCrmLeadResumeInfo(id);
    }
}
